<!doctype html>
<html>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>学生界面</title>
<meta name="description" content="这是学生主页">
<meta name="keywords" content="index">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="icon" type="image/png" href="../img/lysf.ico">
<link rel="stylesheet" href="../amazeui/css/amazeui.min.css" />
<link rel="stylesheet" href="css/admin.css">
<link rel="stylesheet" href="css/app.css">
</head>

<body style="margin-left: 10px;overflow:hidden;" >

	<div id="ref_page" class="am-g">
	
			<div class="tpl-content-page-title" style="margin-bottom: 10px;">填写开题报告</div>

			<div class="am-panel am-panel-default">
				<div class="am-panel-bd">
					<div class="am-scrollable-horizontal">
							<table class="am-table am-table-bordered  am-table-centered am-text-nowrap">
								<tbody>
									<tr>
										<td rowspan="6" style="width: 45px;" class="am-text-middle">开题报告</td>
										<td colspan="2">姓 名</td>
										<td>性别</td>
										<td colspan="2">学 号</td>
										<td colspan="2">专 业</td>
										<td colspan="2">年 级</td>
									</tr>
									<tr id="stuInfo1">
										<td colspan="2"></td>
										<td></td>
										<td colspan="2"></td>
										<td colspan="2"></td>
										<td colspan="2"></td>
									</tr>
									<tr>
										<td rowspan="2" class="am-text-middle">题目</td>
										<td colspan="6" rowspan="2" class="am-text-middle" id="projectName"></td>
										<td colspan="2">课题来源</td>
									</tr>
									<tr>
										<td id="projectFrom"></td>
									</tr>
									<tr style="height: 260px;">
										<td class="am-text-middle" style="width: 30px;">概述</td>
										<td colspan="8"><textarea id="column1" placeholder="说明选题目的、意义，国内外研究现状等"
												style="width: 100%; height: 260px;"></textarea></td>
									</tr>
									<tr style="height: 260px;">
										<td class="am-text-middle">思路及方法</td>
										<td colspan="8"><textarea id="column2"
												style="width: 100%; height: 260px;"></textarea></td>
									</tr>
								</tbody>
							</table>
							<button id="ktbg_btn" type="button" class="am-btn am-btn-primary am-radius am-fr"
								data-am-loading="{spinner: 'circle-o-notch', loadingText: '提交中...', resetText: '提交完成'}">
								提交</button>
					</div>
				</div>
			</div>
				  
	</div>

<script src="../js/jquery.min.js"></script>
<script src="../amazeui/js/amazeui.min.js"></script>
<script src="js/app.js"></script>
<script type="text/javascript">
	$(function() {
		
		 $.ajax({
			   url: "/graduation/studentController/getStuAndProject",
			   type: 'get',
			   dataType:'json',
			   async:false,
			   success: function(data){
				   if(!isNull(data.studentId)){
						$('#stuInfo1').find('td').eq(0).text(data.user.userName);
						var gender;
						if(data.user.userGender==1){
							gender='男';
						}else{
							gender='女';
						}
						$('#stuInfo1').find('td').eq(1).text(gender);
						$('#stuInfo1').find('td').eq(2).text(data.user.userAccount);
						$('#stuInfo1').find('td').eq(3).text(data.classInfo.subject.subjectName);
						$('#stuInfo1').find('td').eq(4).text(data.classInfo.grade.gradeName);
						$('#projectName').text(data.project.projectName);
						$('#projectFrom').text(data.project.projectFrom.projectFromName);
						$('#ktbg_btn').append($('<input>').attr({'type':'hidden','name':'studentId'}).val(data.studentId));
						disBtn(data.studentId);
				   }else{
					   	$('#ktbg_btn').addClass('am-disabled').text('请先选择课题');
						$('#column1').attr('disabled','disabled');
						$('#column2').attr('disabled','disabled');
				   }
			   }
			 });
		 
		//查询数据库是否应该禁用提交按钮
		function disBtn(studentId) {
			if(!isNull(studentId)&&studentId!='undefined'){
				 $.ajax({
					   url: "/graduation/ktbgController/getKtbgByStudentId",
					   type: 'get',
					   dataType:'json',
					   data:{
						   studentId:studentId
					   },
					   async:false,
					   success: function(data){
						   if(!isNull(data.ktbgStatus)){
							   if(data.ktbgStatus==1){
								$('#ktbg_btn').addClass('am-disabled').text('已审核');
								$('#column1').attr('disabled','disabled').text(data.column1);
								$('#column2').attr('disabled','disabled').text(data.column2);
							   }
							}else if(!isNull(data.ktbgId)){
								$('#ktbg_btn').text('更新');
								$('#column1').text(data.column1);
								$('#column2').text(data.column2);
								$('#ktbg_btn').append($('<input>').attr({'type':'hidden','name':'studentId'}).val(data.studentId));
								$('#ktbg_btn').append($('<input>').attr({'type':'hidden','name':'ktbgId'}).val(data.ktbgId));
							}
					   }
					 });
			}
		}
		
		
		//点击提交开题报告按钮
		$('#ktbg_btn').click(function () {
			  var $btn = $(this);
			  var studentId=$btn.find('input:hidden[name=studentId]').val();
			  var ktbgId=$btn.find('input:hidden[name=ktbgId]').val();
			  var column1=$('#column1').val();
			  var column2=$('#column2').val();
			  if(isNull(column1)||isNull(column2)||isNull(studentId)){
				  return;
			  }
			   $.post('/graduation/ktbgController/insertSelective',{
				  ktbgId:ktbgId,
				  studentId:studentId,
				  column1:column1,
				  column2:column2
			  },function(data){
				  if(data){
					  $btn.button('loading');
					    setTimeout(function(){
					    	disableBtn('ktbg_btn','完成');
					  }, 3000);
				  }
			  }); 
			});

	});
</script>
</body>

</html>